<style type="text/css">
    #danhsach{ 
        width: 900px; height: 500px; padding-top: 10px;
        background: gray; overflow: scroll;
    }
    #danhsach table{border-collapse:collapse; margin: 0 auto;}
    #danhsach td{ border: 1px solid #000; padding: 5px;}
	th{text-align:left; padding-right:15px;}
    
</style>
<?php
	if(isset($_POST['sualop']) && ($_POST['sualop'] == "Sửa"))
	{
		$malop = $_POST['malop'];
		$mamh = $_POST['mamh'];
		$magv = $_POST['magv'];
		$maloai = $_POST['loailop'];
		$hk = $_POST['hk'];
		$nam = $_POST['nam'];
		$thu = $_POST['thu'];
		$ca = $_POST['ca'];
		$ph = $_POST['phong'];
		$td = $_POST['toida'];
		
		$_update = mysql_query("UPDATE lop SET MAGIAOVIEN='$magv', MALOAI='$maloai', THU='$thu', CA='$ca', PHONG='$ph', TOIDA='$td' WHERE MALOP='$malop' AND MAMONHOC='$mamh' AND  HOCKY='$hk' AND NAM='$nam'");
		if(!$_update)
		{
			echo "<script>alert('Update khong thanh cong!')</script>";
		}
		else
		{
			echo "<script>alert('Update thanh cong!'); window.location = \"index.php?page=dkmh&function=chinhsua\";</script>";
		}
	}
?>
<div id="function">
    CHỈNH SỬA THÔNG TIN LỚP
</div>


<div id="function_content" style="float: left;">
	<div id="danhsach" style="background: #fff;">
        <table>
            <tr style="background: #247CB9;">
                <td style="text-align: center; color: #fff;">Mã lớp</td>
                <td style="text-align: center; color: #fff;">Mã MH</td>
                <td style="text-align: center; color: #fff;">Tên MH</td>
                <td style="text-align: center; color: #fff;">Mã GV</td>
                <td style="text-align: center; color: #fff;">Tên GV</td>
                <td style="text-align: center; color: #fff;">Mã loại</td>
                <td style="text-align: center; color: #fff;">Học kỳ</td>
                <td style="text-align: center; color: #fff;">Năm</td>
                <td style="text-align: center; color: #fff;">Thứ</td>
                <td style="text-align: center; color: #fff;">Ca</td>
                <td style="text-align: center; color: #fff;">Phòng</td>
                <td style="text-align: center; color: #fff;">Tối đa</td>
            </tr>
        <?php
            $sql = mysql_query("SELECT * FROM monhoc,lop,giaovien WHERE monhoc.MAMONHOC=lop.MAMONHOC AND giaovien.MAGIAOVIEN=lop.MAGIAOVIEN");
            while($rows = mysql_fetch_assoc($sql))
            {
        ?>
        
             <tr>
                 <td style="text-align: center;"><div class="chon_ms">
                        <?php echo $rows['MALOP']; ?></div></td>
                 <td><?php echo $rows['MAMONHOC'] ?></td>
                 <td><?php echo $rows['TENMONHOC']; ?></td>
                 <td><?php echo $rows['MAGIAOVIEN']; ?></td>
                 <td><?php echo $rows['HOTEN']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['MALOAI']; ?></td>                 
                 <td style="text-align: center;"><?php echo $rows['HOCKY']; ?></td>               
                 <td style="text-align: center;"><?php echo $rows['NAM']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['THU']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['CA']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['PHONG']; ?></td>
                 <td style="text-align: center;"><?php echo $rows['TOIDA']; ?></td>
             </tr>
        
        <?php } ?>
        </table> 
    </div>   
</div>

<div id="suattlop" style="width:900px; height:200px;">
    	<form name="suattlop" method="post" action="">
        	<table>
            	<tr><th>Mã Lớp: </th><td><input name="malop" /></td></tr>
                <tr>
                	<th>Mã MH: </th>
                    <td><select name="mamh">
                    	<option>-- Chọn mh --</option>
                        <?php
							$str = mysql_query("SELECT * FROM lop");
							while($r = mysql_fetch_array($str))
							{
								echo "<option value='".$r['MAMONHOC']."'>".$r['MAMONHOC']."</option>";
							}
						?>
                    </select>
                    </td>
                </tr>
                <!--<tr><th>Tên môn học: </th><td><input type="text" name="tenmh" readonly="readonly" /></td></tr>-->
                <tr>
                	<th>Tên GV: </th>
                    <td><select name="magv">
                    	<option>-- Chọn GV --</option>
                        <?php
							$str1 = mysql_query("SELECT * FROM giaovien");
							while($r1 = mysql_fetch_array($str1))
							{
								echo "<option value='".$r1['MAGIAOVIEN']."'>".$r1['HOTEN']."</option>";
							}
						?>
                    </select>
                    </td>
                </tr>
                <!--<tr><th>Họ tên GV: </th><td><input type="text" name="tengv" readonly="readonly" /></td></tr>-->
                <tr>
                	<th>Loại lớp: </th>
                    <td><select name="loailop">
                    	<option>-- Chọn loại lớp --</option>
                        <?php
							$str2 = mysql_query("SELECT * FROM loailop");
							while($r2 = mysql_fetch_array($str2))
							{
								echo "<option value='".$r2['MALOAI']."'>".$r2['LOAILOP']."</option>";
							}
						?>
                    </select>
                    </td>
                </tr>
                <tr><th>Học kỳ: </th><td><input type="text" name="hk" /></td></tr>
                <tr><th>Năm: </th><td><input type="text" name="nam" /></td></tr>
                <tr><th>Thứ: </th><td><input type="text" name="thu" /></td></tr>
                <tr><th>Ca: </th><td><input type="text" name="ca" /></td></tr>
                <tr><th>Phòng: </th><td><input type="text" name="phong" /></td></tr>
                <tr><th>Tối đa: </th><td><input type="text" name="toida" /></td></tr>
                <tr><th></th><td><input type="submit" name="sualop" value="Sửa" style="width:50px;" /></td></tr>
            </table>
        </form>
</div>



<script language="javascript">
	$(document).ready(function(e) {
        $("select[name=mamh]").click(function(e) {
			var mh = $(this).val();
            $("input:text[name=tenmh]").val(mh);
        });
		
		$("select[name=magv]").click(function(e) {
			var gv = $(this).val();
            $("input:text[name=tengv]").val(gv);
        });
    });
</script>